Skip to content

[CodeStyle] Clean up Python 3.9 compatibility code - #79290

Merged
SigureMo merged 2 commits into
PaddlePaddle:developfrom
ShigureNyako:codestyle/py310-compat-cleanup
Jun 10, 2026
Merged

SigureMo merged 2 commits into
PaddlePaddle:developfrom
ShigureNyako:codestyle/py310-compat-cleanup

Conversation

@ShigureNyako

@ShigureNyako ShigureNyako commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Category

Environment Adaptation

PR Types

Improvements

Description

Related to #59685.

Python 3.9 has retired, so this PR removes focused Python <3.10 compatibility code:

  • delete the private _typing.backport shim and use types.EllipsisType directly
  • remove SOT co_lnotab generation and Python <3.10 bytecode rotation/jump branches; keep Python 3.10 and Python 3.11+ paths
  • use co_linetable in the Python 3.10 CodeType path and simplify a Python <3.10 generator-send branch
  • use dataclass kw_only=True directly in the SOT dataclass test
  • handle the requested TODOs with removeprefix / removesuffix
  • CI follow-up: raise CI-H / Fleet Unit test (single card) job timeout to 90min so it can exceed the 60min step runtime when needed

This PR intentionally does not change the ruff target-version. It only handles the Python 3.9 compatibility cleanup / UP036 scope; other py310+ modernization diagnostics should be handled in separate focused PRs.

Validation:

  • ruff check . --target-version=py310 --select UP036 ✅
  • ruff check python/paddle/_typing/__init__.py python/paddle/_typing/basic.py python/paddle/jit/dy2static/convert_call_func.py python/paddle/jit/sot/opcode_translator/executor/pycode_generator.py python/paddle/jit/sot/opcode_translator/executor/variables/iter.py python/paddle/jit/sot/opcode_translator/instruction_utils/instruction_utils.py python/paddle/static/python_op.py test/sot/test_dataclass.py test/sot/test_info_collect.py ✅
  • pre-commit run --files python/paddle/_typing/__init__.py python/paddle/_typing/basic.py python/paddle/jit/dy2static/convert_call_func.py python/paddle/jit/sot/opcode_translator/executor/pycode_generator.py python/paddle/jit/sot/opcode_translator/executor/variables/iter.py python/paddle/jit/sot/opcode_translator/instruction_utils/instruction_utils.py python/paddle/static/python_op.py test/sot/test_dataclass.py test/sot/test_info_collect.py ✅
  • python3.10 -B -m py_compile python/paddle/_typing/__init__.py python/paddle/_typing/basic.py python/paddle/jit/dy2static/convert_call_func.py python/paddle/jit/sot/opcode_translator/executor/pycode_generator.py python/paddle/jit/sot/opcode_translator/executor/variables/iter.py python/paddle/jit/sot/opcode_translator/instruction_utils/instruction_utils.py python/paddle/static/python_op.py test/sot/test_dataclass.py test/sot/test_info_collect.py ✅
  • pre-commit run --files .github/workflows/H-Coverage.yml ✅

Focused SOT runtime tests were not runnable in this local source checkout because there is no built Paddle libpaddle/installed wheel available (and the local Python 3.10 env also lacks test dependency numpy).

是否引起精度变化

否

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

@SigureMo 麻烦有空帮忙 review 一下。已自查 diff,并验证 ruff check . --target-version=py310 --select UP036、变更文件 ruff/pre-commit、以及 python3.10 -B -m py_compile 均通过;本 PR 未修改 ruff target-version,只聚焦 Python 3.9 退场兼容清理。

Comment thread python/paddle/_typing/backport.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backport 文件可以直接清理了,相关地方直接用对应类型就好了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,已按建议删除 python/paddle/_typing/backport.py,并把相关引用改为直接使用 types.EllipsisType:

  • python/paddle/_typing/basic.py
  • python/paddle/_typing/__init__.py

更新后 commit: 64965e8
验证:ruff check . --target-version=py310 --select UP036、变更文件 ruff/pre-commit、python3.10 -B -m py_compile 均通过。

@ShigureNyako
ShigureNyako force-pushed the codestyle/py310-compat-cleanup branch from a248a3e to 64965e8 Compare June 9, 2026 15:38
Comment thread python/paddle/_typing/__init__.py Outdated

# Backport
from .backport import EllipsisType as EllipsisType
from types import EllipsisType as EllipsisType

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也不要了啊,你直接在用它的地方 from types import EllipsisType 不就好了?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,已移除 python/paddle/_typing/__init__.py 里的 EllipsisType re-export;现在只在实际使用处 python/paddle/_typing/basic.py 直接 from types import EllipsisType。

更新后 commit: a5c473b
验证:ruff check . --target-version=py310 --select UP036、变更文件 ruff/pre-commit、python3.10 -B -m py_compile 均通过。

@ShigureNyako
ShigureNyako force-pushed the codestyle/py310-compat-cleanup branch from 64965e8 to a5c473b Compare June 9, 2026 15:55
SigureMo
SigureMo previously approved these changes Jun 9, 2026

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@SigureWang

Copy link
Copy Markdown
Contributor

代码审查结论:未发现需要阻塞合入的问题。

已重点检查本 PR 对 Python 3.9 兼容分支的清理,当前实现与 Python 3.10+ 目标一致:

  • _typing.backport 删除后,仓库内未发现继续依赖 paddle._typing.backport 或 from paddle._typing import EllipsisType 的直接引用;实际使用处已改为 types.EllipsisType。
  • CodeType 构造仍按 >=3.11 与 3.10 分支处理,co_linetable / co_exceptiontable 参数顺序与目标版本匹配。
  • SOT 字节码生成中移除 Python <3.10 的 co_lnotab、旧 jump arg 和 ROT_* 兼容逻辑,和本 PR 的 Python 3.9 退场范围一致。
  • removeprefix / removesuffix 与 dataclass kw_only=True 的改动均依赖 Python 3.10+,符合本次清理目标。

建议后续等当前 PR-CI-SOT / Build and Test 重跑完成;如果 SOT 仍失败,优先查看 Python 3.10 / 3.11 runtime 日志,重点关注 pycode_generator.py、generator send 和 jump relocation 相关用例。

@paddle-bot paddle-bot Bot added the contributor External developers label Jun 9, 2026
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

CI 跟进:当前 PR-CI-SOT / Build and Test 失败来自 self-hosted runner 断连,不是用例失败:

The self-hosted runner lost communication with the server.

我已在前面发过 /re-run all-failed,但目前状态仍指向原失败 job;我这边尝试直接 rerun failed jobs 时 GitHub 提示需要 repository admin 权限。若 bot 没有触发重跑,麻烦有权限的同学帮忙重跑一下该 job。

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@9d69b2f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...sot/opcode_translator/executor/pycode_generator.py 50.00% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (75.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #79290   +/-   ##
==========================================
  Coverage           ?   75.00%           
==========================================
  Files              ?        5           
  Lines              ?        8           
  Branches           ?        0           
==========================================
  Hits               ?        6           
  Misses             ?        2           
  Partials           ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SigureMo

Copy link
Copy Markdown
Collaborator

The job has exceeded the maximum execution time of 1h0m0s

@ShigureNyako 你去把 CI-H / Fleet Unit test (single card) job 总时长提高到 90min,虽然 Single card test step 提高了,但是总时长没增加啊,还是会 timeout 啊 @swgu98

@ShigureNyako

ShigureNyako commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@SigureMo Done,已按要求把 CI-H / Fleet Unit test (single card) 的 job 总时长从 60min 提到 90min;Single card test step 本身保持 60min 不变。

变更:.github/workflows/H-Coverage.yml
提交:01a1740aae(普通增量 commit,未 force-push)
验证:pre-commit run --files .github/workflows/H-Coverage.yml 通过。

@SigureMo

Copy link
Copy Markdown
Collaborator

@ShigureNyako 好,这次只要 CI-H / Fleet Unit test (single card) 过了就可以合入了,CI 过了的时候可以 @ 我一下

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

2 similar comments
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

@SigureMo 看到已加 skip-ci: all。当前 PR 代码没有再改,失败项仍是 Fleet 单/多卡和 Linux-CPU 的 CI 问题;这边不继续重跑了。

目前 GitHub 状态里之前的 approval 已因增量 commit 变为 stale/dismissed,reviewDecision 仍是 REVIEW_REQUIRED。麻烦有空再 approve 一下,之后就可以继续合入流程。

@SigureMo
SigureMo merged commit 255dd8e into PaddlePaddle:develop Jun 10, 2026
140 of 147 checks passed
@SigureMo
SigureMo deleted the codestyle/py310-compat-cleanup branch June 10, 2026 05:26
@SigureMo SigureMo mentioned this pull request Jun 14, 2026
12 of 21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers skip-ci: all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants